package com.atguigu.gmall.order.config;

import com.atguigu.gmall.common.constant.MqConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
//延迟订单配置
public class DelayedOrderConfig {

    @Bean
    public CustomExchange delayExchange(){
        //设置额外的参数
        HashMap<String,Object> hashMap = new HashMap<>();
        hashMap.put("x-delayed-type","direct");
        //设置交换机的参数
        return new CustomExchange(MqConst.EXCHANGE_DIRECT_ORDER_CANCEL,"x-delayed-message",true,false,hashMap);
    }

    @Bean
    public Queue delayQueue(){
        //  返回
        return new Queue(MqConst.QUEUE_ORDER_CANCEL,true,false,false);
    }
    @Bean
    public Binding delayBinding(){
        //  返回
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with(MqConst.ROUTING_ORDER_CANCEL).noargs();
    }

}
